package com.bsu.ascm.operation;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;

import com.bsu.ascm.Ascm;
import com.bsu.ascm.R;
import com.bsu.ascm.operation.base.OperationBase;
import com.bsu.ascm.tool.Utils;

public class MainMenu extends Activity{
	private GridView gridview = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);						//设置横屏
        requestWindowFeature(Window.FEATURE_NO_TITLE);											//无title  
        getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,    					//全屏
                       WindowManager.LayoutParams. FLAG_FULLSCREEN);
		
		setContentView(R.layout.mainmenu);
		init();
	}

//	@Override
//	public boolean onKeyDown(int keyCode, KeyEvent event) {
//    	switch(keyCode){
//	    	case KeyEvent.KEYCODE_MENU:
//	    		super.openOptionsMenu();
//	    		break;
//	    	case KeyEvent.KEYCODE_BACK:											//当前layout为主界面时弹出退出界面
//	   			Utils.appExit(this);
//	    		break;
//	    	default:
//	    		break;
//    	}
//		return true;
//	}

	/**
	 * 初始化界面
	 */
	public void init(){
		gridview = (GridView)findViewById(R.id.gridView1);
		ArrayList<HashMap<String,Object>> lsImageItem = new ArrayList<HashMap<String,Object>>();
		//增加10个图标
		for(int i=0;i<10;i++){
			HashMap<String,Object> map = new HashMap<String,Object>();
			map.put("ItemImage", R.drawable.icon);
			map.put("ItemText", "功能."+String.valueOf(i));
			lsImageItem.add(map);
		}
		lsImageItem.get(0).put("ItemText", "质量目标完成情况");
		lsImageItem.get(1).put("ItemText", "接收看板");
		lsImageItem.get(2).put("ItemText", "LCD");
		
		//生成图标代理
		SimpleAdapter saImageItems = new SimpleAdapter(this,
				lsImageItem,R.layout.mainmenuitem,
				new String[] {"ItemImage","ItemText"},
				new int[]{R.id.ItemImage,R.id.ItemText});
		gridview.setAdapter(saImageItems);
		gridview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
			/**
			 * 响应点击事件
			 */
			@Override
			public void onItemClick(AdapterView<?> parent, View v, int position,
					long id) {
				// TODO Auto-generated method stub
				Intent intent = null;
				if(position==0)
					intent = new Intent(MainMenu.this,com.bsu.ascm.operation.QualityObjectLineChart.class);
				else if(position==2)
					intent = new Intent(MainMenu.this,com.bsu.ascm.operation.LCD.class);
				else if(position==1)
					intent = new Intent(MainMenu.this,com.bsu.ascm.operation.ReceiveKanban.class);
				
				if(intent!=null)
					MainMenu.this.startActivity(intent);
			}
		});
	}
}
